/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm_candidatos;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class CandidatosDAO {
	public static Candidatos loadCandidatosByORMID(int id_candidato) throws PersistentException {
		try {
			PersistentSession session = orm_candidatos.CandidatosVEPDSPersistentManager.instance().getSession();
			return loadCandidatosByORMID(session, id_candidato);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos getCandidatosByORMID(int id_candidato) throws PersistentException {
		try {
			PersistentSession session = orm_candidatos.CandidatosVEPDSPersistentManager.instance().getSession();
			return getCandidatosByORMID(session, id_candidato);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos loadCandidatosByORMID(int id_candidato, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm_candidatos.CandidatosVEPDSPersistentManager.instance().getSession();
			return loadCandidatosByORMID(session, id_candidato, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos getCandidatosByORMID(int id_candidato, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm_candidatos.CandidatosVEPDSPersistentManager.instance().getSession();
			return getCandidatosByORMID(session, id_candidato, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos loadCandidatosByORMID(PersistentSession session, int id_candidato) throws PersistentException {
		try {
			return (Candidatos) session.load(orm_candidatos.Candidatos.class, new Integer(id_candidato));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos getCandidatosByORMID(PersistentSession session, int id_candidato) throws PersistentException {
		try {
			return (Candidatos) session.get(orm_candidatos.Candidatos.class, new Integer(id_candidato));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos loadCandidatosByORMID(PersistentSession session, int id_candidato, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Candidatos) session.load(orm_candidatos.Candidatos.class, new Integer(id_candidato), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos getCandidatosByORMID(PersistentSession session, int id_candidato, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Candidatos) session.get(orm_candidatos.Candidatos.class, new Integer(id_candidato), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos[] listCandidatosByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm_candidatos.CandidatosVEPDSPersistentManager.instance().getSession();
			return listCandidatosByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos[] listCandidatosByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm_candidatos.CandidatosVEPDSPersistentManager.instance().getSession();
			return listCandidatosByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos[] listCandidatosByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm_candidatos.Candidatos as Candidatos");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Candidatos[]) list.toArray(new Candidatos[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos[] listCandidatosByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm_candidatos.Candidatos as Candidatos");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Candidatos[]) list.toArray(new Candidatos[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos loadCandidatosByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm_candidatos.CandidatosVEPDSPersistentManager.instance().getSession();
			return loadCandidatosByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos loadCandidatosByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm_candidatos.CandidatosVEPDSPersistentManager.instance().getSession();
			return loadCandidatosByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos loadCandidatosByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Candidatos[] candidatoses = listCandidatosByQuery(session, condition, orderBy);
		if (candidatoses != null && candidatoses.length > 0)
			return candidatoses[0];
		else
			return null;
	}
	
	public static Candidatos loadCandidatosByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Candidatos[] candidatoses = listCandidatosByQuery(session, condition, orderBy, lockMode);
		if (candidatoses != null && candidatoses.length > 0)
			return candidatoses[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateCandidatosByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm_candidatos.CandidatosVEPDSPersistentManager.instance().getSession();
			return iterateCandidatosByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCandidatosByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm_candidatos.CandidatosVEPDSPersistentManager.instance().getSession();
			return iterateCandidatosByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCandidatosByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm_candidatos.Candidatos as Candidatos");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateCandidatosByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm_candidatos.Candidatos as Candidatos");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos createCandidatos() {
		return new orm_candidatos.Candidatos();
	}
	
	public static boolean save(orm_candidatos.Candidatos candidatos) throws PersistentException {
		try {
			orm_candidatos.CandidatosVEPDSPersistentManager.instance().saveObject(candidatos);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean delete(orm_candidatos.Candidatos candidatos) throws PersistentException {
		try {
			orm_candidatos.CandidatosVEPDSPersistentManager.instance().deleteObject(candidatos);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean refresh(orm_candidatos.Candidatos candidatos) throws PersistentException {
		try {
			orm_candidatos.CandidatosVEPDSPersistentManager.instance().getSession().refresh(candidatos);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean evict(orm_candidatos.Candidatos candidatos) throws PersistentException {
		try {
			orm_candidatos.CandidatosVEPDSPersistentManager.instance().getSession().evict(candidatos);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static Candidatos loadCandidatosByCriteria(CandidatosCriteria candidatosCriteria) {
		Candidatos[] candidatoses = listCandidatosByCriteria(candidatosCriteria);
		if(candidatoses == null || candidatoses.length == 0) {
			return null;
		}
		return candidatoses[0];
	}
	
	public static Candidatos[] listCandidatosByCriteria(CandidatosCriteria candidatosCriteria) {
		return candidatosCriteria.listCandidatos();
	}
}
